Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class ctlDotsValue

    Inherits System.Windows.Forms.UserControl

    Private Dots(15) As Boolean
    Private m_startValue As Integer = 5
    Private m_dotValue As Integer = 1  ' the value of each dot. StartValue + (Dotvalue * #dots)= total value

    Private c_ACTIVECOLOR As Color = System.Drawing.Color.CornflowerBlue
    Private c_INACTIVECOLOR As Color = System.Drawing.Color.LightSlateGray

    Public Event TotalValueChanged(ByVal NewValue As Integer)

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        Dots(0) = True

        ColorizeDots()

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlBorder As System.Windows.Forms.Panel
    Friend WithEvents pnlThirteen As System.Windows.Forms.Panel
    Friend WithEvents pnlTwelve As System.Windows.Forms.Panel
    Friend WithEvents pnlEleven As System.Windows.Forms.Panel
    Friend WithEvents pnlTen As System.Windows.Forms.Panel
    Friend WithEvents pnlNine As System.Windows.Forms.Panel
    Friend WithEvents pnlEight As System.Windows.Forms.Panel
    Friend WithEvents pnlSeven As System.Windows.Forms.Panel
    Friend WithEvents pnlSix As System.Windows.Forms.Panel
    Friend WithEvents pnlFive As System.Windows.Forms.Panel
    Friend WithEvents pnlFour As System.Windows.Forms.Panel
    Friend WithEvents pnlThree As System.Windows.Forms.Panel
    Friend WithEvents pnlTwo As System.Windows.Forms.Panel
    Friend WithEvents pnlOne As System.Windows.Forms.Panel
    Friend WithEvents pnlFifteen As System.Windows.Forms.Panel
    Friend WithEvents pnlFourteen As System.Windows.Forms.Panel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.pnlBorder = New System.Windows.Forms.Panel()
        Me.pnlFifteen = New System.Windows.Forms.Panel()
        Me.pnlFourteen = New System.Windows.Forms.Panel()
        Me.pnlThirteen = New System.Windows.Forms.Panel()
        Me.pnlTwelve = New System.Windows.Forms.Panel()
        Me.pnlEleven = New System.Windows.Forms.Panel()
        Me.pnlTen = New System.Windows.Forms.Panel()
        Me.pnlNine = New System.Windows.Forms.Panel()
        Me.pnlEight = New System.Windows.Forms.Panel()
        Me.pnlSeven = New System.Windows.Forms.Panel()
        Me.pnlSix = New System.Windows.Forms.Panel()
        Me.pnlFive = New System.Windows.Forms.Panel()
        Me.pnlFour = New System.Windows.Forms.Panel()
        Me.pnlThree = New System.Windows.Forms.Panel()
        Me.pnlTwo = New System.Windows.Forms.Panel()
        Me.pnlOne = New System.Windows.Forms.Panel()
        Me.pnlBorder.SuspendLayout()
        Me.SuspendLayout()
        '
        'pnlBorder
        '
        Me.pnlBorder.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlBorder.Controls.AddRange(New System.Windows.Forms.Control() {Me.pnlFifteen, Me.pnlFourteen, Me.pnlThirteen, Me.pnlTwelve, Me.pnlEleven, Me.pnlTen, Me.pnlNine, Me.pnlEight, Me.pnlSeven, Me.pnlSix, Me.pnlFive, Me.pnlFour, Me.pnlThree, Me.pnlTwo, Me.pnlOne})
        Me.pnlBorder.Name = "pnlBorder"
        Me.pnlBorder.Size = New System.Drawing.Size(120, 20)
        Me.pnlBorder.TabIndex = 23
        '
        'pnlFifteen
        '
        Me.pnlFifteen.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlFifteen.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlFifteen.Location = New System.Drawing.Point(103, 4)
        Me.pnlFifteen.Name = "pnlFifteen"
        Me.pnlFifteen.Size = New System.Drawing.Size(8, 10)
        Me.pnlFifteen.TabIndex = 54
        Me.pnlFifteen.Tag = "0"
        '
        'pnlFourteen
        '
        Me.pnlFourteen.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlFourteen.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlFourteen.Location = New System.Drawing.Point(96, 4)
        Me.pnlFourteen.Name = "pnlFourteen"
        Me.pnlFourteen.Size = New System.Drawing.Size(8, 10)
        Me.pnlFourteen.TabIndex = 53
        Me.pnlFourteen.Tag = "0"
        '
        'pnlThirteen
        '
        Me.pnlThirteen.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlThirteen.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlThirteen.Location = New System.Drawing.Point(89, 4)
        Me.pnlThirteen.Name = "pnlThirteen"
        Me.pnlThirteen.Size = New System.Drawing.Size(8, 10)
        Me.pnlThirteen.TabIndex = 52
        Me.pnlThirteen.Tag = "0"
        '
        'pnlTwelve
        '
        Me.pnlTwelve.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlTwelve.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlTwelve.Location = New System.Drawing.Point(82, 4)
        Me.pnlTwelve.Name = "pnlTwelve"
        Me.pnlTwelve.Size = New System.Drawing.Size(8, 10)
        Me.pnlTwelve.TabIndex = 51
        Me.pnlTwelve.Tag = "0"
        '
        'pnlEleven
        '
        Me.pnlEleven.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlEleven.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlEleven.Location = New System.Drawing.Point(75, 4)
        Me.pnlEleven.Name = "pnlEleven"
        Me.pnlEleven.Size = New System.Drawing.Size(8, 10)
        Me.pnlEleven.TabIndex = 50
        Me.pnlEleven.Tag = "0"
        '
        'pnlTen
        '
        Me.pnlTen.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlTen.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlTen.Location = New System.Drawing.Point(68, 4)
        Me.pnlTen.Name = "pnlTen"
        Me.pnlTen.Size = New System.Drawing.Size(8, 10)
        Me.pnlTen.TabIndex = 48
        Me.pnlTen.Tag = "0"
        '
        'pnlNine
        '
        Me.pnlNine.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlNine.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlNine.Location = New System.Drawing.Point(61, 4)
        Me.pnlNine.Name = "pnlNine"
        Me.pnlNine.Size = New System.Drawing.Size(8, 10)
        Me.pnlNine.TabIndex = 47
        Me.pnlNine.Tag = "0"
        '
        'pnlEight
        '
        Me.pnlEight.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlEight.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlEight.Location = New System.Drawing.Point(54, 4)
        Me.pnlEight.Name = "pnlEight"
        Me.pnlEight.Size = New System.Drawing.Size(8, 10)
        Me.pnlEight.TabIndex = 46
        Me.pnlEight.Tag = "0"
        '
        'pnlSeven
        '
        Me.pnlSeven.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlSeven.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlSeven.Location = New System.Drawing.Point(47, 4)
        Me.pnlSeven.Name = "pnlSeven"
        Me.pnlSeven.Size = New System.Drawing.Size(8, 10)
        Me.pnlSeven.TabIndex = 45
        Me.pnlSeven.Tag = "0"
        '
        'pnlSix
        '
        Me.pnlSix.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlSix.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlSix.Location = New System.Drawing.Point(40, 4)
        Me.pnlSix.Name = "pnlSix"
        Me.pnlSix.Size = New System.Drawing.Size(8, 10)
        Me.pnlSix.TabIndex = 44
        Me.pnlSix.Tag = "0"
        '
        'pnlFive
        '
        Me.pnlFive.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlFive.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlFive.Location = New System.Drawing.Point(33, 4)
        Me.pnlFive.Name = "pnlFive"
        Me.pnlFive.Size = New System.Drawing.Size(8, 10)
        Me.pnlFive.TabIndex = 43
        Me.pnlFive.Tag = "0"
        '
        'pnlFour
        '
        Me.pnlFour.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlFour.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlFour.Location = New System.Drawing.Point(26, 4)
        Me.pnlFour.Name = "pnlFour"
        Me.pnlFour.Size = New System.Drawing.Size(8, 10)
        Me.pnlFour.TabIndex = 42
        Me.pnlFour.Tag = "0"
        '
        'pnlThree
        '
        Me.pnlThree.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlThree.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlThree.Location = New System.Drawing.Point(19, 4)
        Me.pnlThree.Name = "pnlThree"
        Me.pnlThree.Size = New System.Drawing.Size(8, 10)
        Me.pnlThree.TabIndex = 40
        Me.pnlThree.Tag = "0"
        '
        'pnlTwo
        '
        Me.pnlTwo.BackColor = System.Drawing.Color.LightSlateGray
        Me.pnlTwo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlTwo.Location = New System.Drawing.Point(12, 4)
        Me.pnlTwo.Name = "pnlTwo"
        Me.pnlTwo.Size = New System.Drawing.Size(8, 10)
        Me.pnlTwo.TabIndex = 39
        Me.pnlTwo.Tag = "0"
        '
        'pnlOne
        '
        Me.pnlOne.BackColor = System.Drawing.Color.CornflowerBlue
        Me.pnlOne.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlOne.Location = New System.Drawing.Point(5, 4)
        Me.pnlOne.Name = "pnlOne"
        Me.pnlOne.Size = New System.Drawing.Size(8, 10)
        Me.pnlOne.TabIndex = 38
        Me.pnlOne.Tag = "1"
        '
        'ctlDotsValue
        '
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.pnlBorder})
        Me.Font = New System.Drawing.Font("Haettenschweiler", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "ctlDotsValue"
        Me.Size = New System.Drawing.Size(120, 20)
        Me.pnlBorder.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region


    Private Sub ColorizeDots()
        Dim b As Integer
        Dim highDot As Integer

        highDot = DotCount() - 1

        For b = 0 To Dots.GetUpperBound(0)
            If b <= highDot Then
                ColorDamnedDot(b, c_ACTIVECOLOR)
            Else
                ColorDamnedDot(b, c_INACTIVECOLOR)
            End If
        Next

    End Sub

    Private Sub ColorDamnedDot(ByVal index As Integer, ByVal col As System.Drawing.Color)
        Select Case index
            Case 0 : pnlOne.BackColor = col
            Case 1 : pnlTwo.BackColor = col
            Case 2 : pnlThree.BackColor = col
            Case 3 : pnlFour.BackColor = col
            Case 4 : pnlFive.BackColor = col
            Case 5 : pnlSix.BackColor = col
            Case 6 : pnlSeven.BackColor = col
            Case 7 : pnlEight.BackColor = col
            Case 8 : pnlNine.BackColor = col
            Case 9 : pnlTen.BackColor = col
            Case 10 : pnlEleven.BackColor = col
            Case 11 : pnlTwelve.BackColor = col
            Case 12 : pnlThirteen.BackColor = col
            Case 13 : pnlFourteen.BackColor = col
            Case 14 : pnlFifteen.BackColor = col
        End Select
    End Sub

    Private Function DotCount() As Integer
        Dim b As Integer
        Dim count As Integer

        For b = 0 To Dots.GetUpperBound(0)
            If Dots(b) = True Then
                count += 1
            Else
                ' once we hit false, we're done
                Exit For
            End If
        Next

        Return count

    End Function

    Public Property TotalValue() As Integer
        Get
            Dim dots As Integer = DotCount()
            Return (m_startValue + (dots * m_dotValue))
        End Get
        Set(ByVal Value As Integer)
            ' determine how many dots should be lit up considering the value provided.
            Dim temp As Integer
            Dim dotCount As Integer
            Try
                temp = Value - m_startValue
                dotCount = CType((temp / m_dotValue), Integer)

                Dim b As Integer
                For b = 0 To Dots.GetUpperBound(0)
                    If (dotCount - 1) >= b Then
                        Dots(b) = True
                    Else
                        Dots(b) = False
                    End If
                Next
            Catch

            End Try

            ColorizeDots()

        End Set
    End Property

    Public Property startValue() As Integer
        Get
            Return m_startValue
        End Get
        Set(ByVal Value As Integer)
            m_startValue = Value
        End Set
    End Property

    Public Property dotValue() As Integer
        Get
            Return m_dotValue
        End Get
        Set(ByVal Value As Integer)
            m_dotValue = Value
        End Set
    End Property

    Private Sub DotSelect(ByVal Dot As Integer, ByVal Deselect As Boolean)
        Dim i As Integer

        If Deselect Then
            ' deselect down to the provided dot
            For i = Dot - 1 To Dots.GetUpperBound(0)
                Dots(i) = False
            Next
        Else
            ' select up to the provided dot
            For i = 0 To Dot - 1
                Dots(i) = True
            Next
        End If

        ColorizeDots()
        Dim tVal As Integer
        tVal = TotalValue
        RaiseEvent TotalValueChanged(tVal)

    End Sub

    Private Sub pnlOne_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlOne.Click
        'Dim index As Integer = 0

        'If Dots(index) = True Then
        '    DotSelect(index + 1, True)
        'Else
        '    DotSelect(index - 1, False)
        'End If

        ' this one is always selected

    End Sub

    Private Sub pnlTwo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlTwo.Click
        Dim index As Integer = 1

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Private Sub pnlThree_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlThree.Click
        Dim index As Integer = 2

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Private Sub pnlFour_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlFour.Click
        Dim index As Integer = 3

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Private Sub pnlFive_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlFive.Click
        Dim index As Integer = 4

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Private Sub pnlSix_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlSix.Click
        Dim index As Integer = 5

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Private Sub pnlSeven_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlSeven.Click
        Dim index As Integer = 6

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Private Sub pnlEight_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlEight.Click
        Dim index As Integer = 7

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Private Sub pnlNine_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlNine.Click
        Dim index As Integer = 8

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Private Sub pnlTen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlTen.Click
        Dim index As Integer = 9

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Private Sub pnlEleven_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlEleven.Click
        Dim index As Integer = 10

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Private Sub pnlTwelve_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlTwelve.Click
        Dim index As Integer = 11

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Private Sub pnlThirteen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlThirteen.Click
        Dim index As Integer = 12

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Private Sub pnlFourteen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlFourteen.Click
        Dim index As Integer = 13

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Private Sub pnlFifteen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnlFifteen.Click
        Dim index As Integer = 14

        If Dots(index) = True Then
            DotSelect(index + 1, True)
        Else
            DotSelect(index + 1, False)
        End If

    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)

        Exit Sub

        'Dim g As Graphics = pnlFifteen.CreateGraphics
        'g.DrawString("0", Me.Font, Brushes.Black, -1, -2)
        'g.Dispose()

        'g = pnlFourteen.CreateGraphics
        'g.DrawString("0", Me.Font, Brushes.Black, -1, -2)
        'g.Dispose()

        'g = pnlThirteen.CreateGraphics
        'g.DrawString("13", Me.Font, Brushes.Black, -1, -2)
        'g.Dispose()

        'g = pnlTwelve.CreateGraphics
        'g.DrawString("12", Me.Font, Brushes.Black, -1, -2)
        'g.Dispose()

        'g = pnlEleven.CreateGraphics
        'g.DrawString("11", Me.Font, Brushes.Black, -1, -2)
        'g.Dispose()

        'g = pnlTen.CreateGraphics
        'g.DrawString("10", Me.Font, Brushes.Black, -1, -2)
        'g.Dispose()

        'g = pnlNine.CreateGraphics
        'g.DrawString("9", Me.Font, Brushes.Black, -1, -2)
        'g.Dispose()



    End Sub

End Class
